extends partial/layout

block content
  include partial/message
  header
    .wrap
      -if(parent)
        a.back(href=parent)
      a.home(href='/') ShareList
  section.wrap.auth
    h3 #{name}
    div
      .form-group
        input.sl-input(id="j_user",type='text', name='user', placeholder=__('auth_user_placeholder'))
        input.sl-input(id="j_passwd",type='password', name='passwd', placeholder=__('auth_passwd_placeholder'))
      button.sl-button.btn-primary(type="button")= __('ok')
  script(src='https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js')
  
  script.
    function checkAuth(){
      let passwd = $('#j_passwd').val(), user = $('#j_user').val() , path = location.pathname
      $('button').addClass('loading')
      $.ajax({
        url:'', dataType:'json', method:'POST',
        data:{ act:'auth' , path : path , user:user , passwd : passwd },
        success:function(resp){
          $('button').removeClass('loading')
          if(resp.status == 0){
            if(resp.rurl){
              location.href = resp.rurl
            }else{
              location.reload()
            }
          }else{
            alert(resp.message)
          }
        },
        error:function(resp){
          $('button').removeClass('loading')

        }
      })
    }
    $(function(){
      $('#j_passwd').on('keypress' , function(e){
        if(e.keyCode == "13"){
          checkAuth()
        }
      })
      $('button').on('click' , function(){
        checkAuth()
      })

      var item
      if($('.item').length){
        item = $('.item:first').clone()
        item.find('input').val('')
      }
      $('body').on('click','.create-path' , function(){
        $('.group-path').append( item.clone() )
      })
      .on('click' ,'.remove-path' , function(){
        $(this).parents('.item').remove()
      })
    })
      

  include partial/footer